package tools

import (
	"gitee.com/jjawesomejj/awesome-util/config"
	"gitee.com/jjawesomejj/awesome-util/helper/encryptHelper"
)

func getDefaultEncryptKey() string {
	key := config.GetConfigByKey("defaultEncryptKey", func() interface{} {
		return "ukzeVEDgHP0sNRIj9atiScxhFbZ256O3"
	}).(string)
	if len(key) != 32 {
		panic("加密的key必须为32位数")
	}
	return key
}

func Encrypt(data string) string {
	return encryptHelper.BlowfishECBEncrypt(data, getDefaultEncryptKey())
}

func Decrypt(data string) (string, error) {
	return encryptHelper.BlowfishECBDecrypt(data, getDefaultEncryptKey())
}
